---
title: "2. Add the GraphQL schema"
---

This tutorial uses a modified version of the GraphQL server you build as part of [the Apollo full-stack tutorial](https://www.apollographql.com/docs/tutorial/introduction/). You can visit [that server's GraphOS Studio Sandbox Explorer](https://studio.apollographql.com/sandbox/explorer?endpoint=https%3A%2F%2Fapollo-fullstack-tutorial.herokuapp.com%2Fgraphql) to explore its schema without needing to be logged in:

<img src="images/sandbox_landing.png" alt="The Sandbox query explorer" class="screenshot"/>

You'll know that this Sandbox instance is pointed at our server because its URL, `https://apollo-fullstack-tutorial.herokuapp.com`, is in the box at the top left of the page. If Sandbox is properly connected, you'll see a green dot:

<img src="images/sandbox_green_dot.png" alt="A closeup of the URL box with a dot indicating it's connected" class="screenshot"/>

The schema defines which GraphQL operations your server can execute. At the top left, click the schema icon to get an overview of your schema:

<img src="images/schema_icon.png" alt="The schema icon to click" class="screenshot"/>

In the **Reference** tab, you can now see a list of all of the things available to you as a consumer of this API, along with available fields on all objects:

<img src="images/sandbox_schema_reference.png" alt="Apollo sandbox showing the schema reference" class="screenshot"/>

## Download your server's schema

Apollo Kotlin requires a schema to generate type-safe models and code from your queries. There are multiple ways to get a schema. For example, you can go to the SDL tab and download the raw SDL schema using GraphOS Studio Sandbox.

In this tutorial, we will use the Gradle task that is created by the Apollo plugin automatically. Since GraphQL supports [introspection](https://graphql.org/learn/introspection/), this will work with any GraphQL endpoint that has introspection enabled.

First, add the URL of the GraphQL endpoint and the desired location of the schena to the Apollo Gradle configuration:

```kotlin title="app/build.gradle.kts"
apollo {
  service("service") {
    packageName.set("com.example.rocketreserver")
    introspection { // highlight-line
      endpointUrl.set("https://apollo-fullstack-tutorial.herokuapp.com/graphql") // highlight-line
      schemaFile.set(file("src/main/graphql/schema.graphqls")) // highlight-line
    } // highlight-line
  }
}
```

Then, from the root of the project, run this command in Android Studio's Terminal tab:

```shell title="(shell)"
./gradlew :app:downloadServiceApolloSchemaFromIntrospection
```

This will download a `schema.graphqls` file from your endpoint to `app/src/main/graphql/schema.graphqls`.

If you installed the [Android Studio Plugin](https://www.apollographql.com/docs/kotlin/testing/android-studio-plugin/), you can also download the schema from <kbd>Tools</kbd> | <kbd>Apollo</kbd> | <kbd>Download Schema</kbd>.

Next, [write your first query](03-write-your-first-query) that uses this schema.
